package com.yiwyn.Structural.decorator;

import lombok.AllArgsConstructor;

/**
 * 装饰器模式
 */

public class DecoratorDemo {


    public static void main(String[] args) {
        Text text = new PlainText("Hello World");
        Text decoratorText = new ItalicDecorator(new BoldDecorator(text));
        System.out.println(decoratorText.formatText());
    }

    // 文本
    interface Text {
        String formatText();
    }

    // 简单文本
    @AllArgsConstructor
    static class PlainText implements Text {

        private String text;

        @Override
        public String formatText() {
            return text;
        }
    }

    // BoldDecorator 加粗
    @AllArgsConstructor
    static class BoldDecorator implements Text {

        private Text text;

        @Override
        public String formatText() {
            return "<b>" + text.formatText() + "</b>";
        }
    }

    // ItalicDecorator
    @AllArgsConstructor
    static class ItalicDecorator implements Text {

        private Text text;

        @Override
        public String formatText() {
            return "<i>" + text.formatText() + "< /i>";
        }
    }


}
